﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Web.Services;


public partial class details : System.Web.UI.Page
{
    VLGDataContext _db2 = new VLGDataContext();
    CommonPage _com = new CommonPage();
    protected void Page_Load(object sender, EventArgs e)
    {
        Session["currentItem"] = "giohang";
        if (!IsPostBack)
            this.loadData();
    }

    void loadData()
    {
        string stCateID = Request.QueryString["c"];
        string tukhoa = Request.QueryString["search"];
        string tuychon = Request.QueryString["opt"];
        string stCate = null;
        string tagsCate = "";
        int _idCus;
        try
        {
            _idCus = _com.Customer.idAcc;
        }
        catch
        {
            _idCus = 0;
        }
        try
        {
            Category cats = _db2.Categories.Single(paxa => paxa.TenCate_E.Equals(stCateID));
            stCate = cats.idCategory.ToString();
            tagsCate = cats.Tags;

        }
        catch
        {
            stCate = null;
            tagsCate = "việc làm gấp , việc làm , gấp";

        }
        if (_idCus != 0)
        {
            //Response.Write(stCate);
            if (stCate == null && tukhoa == null && tuychon == null)
            {
                //   Response.Write(_idCus);
                var itemGigAll = from gig6 in _db2.Gigs
                                 where gig6.TrangThai == (int)EnumGigStatus.GigHien && gig6.Duyet == true
                                 orderby gig6.idGig
                                 select new
                                 {
                                     gig6.idGig,
                                     gig6.TenCongViec,
                                     gig6.VLGAccount.UsernameE,
                                     gig6.idCategory,
                                     gig6.UrlHinh1,
                                     gig6.MoTaCV,
                                     gig6.VLGAccount.ipAddress,
                                     gig6.VLGAccount.TenQuocGia,
                                     gig6.TenCongViec_KD,
                                     gig6.Tags,
                                     gig6.Category.TenCate_E,
                                     CssClass = (from cd in _db2.CollectionDetails
                                                 where cd.idGig == Convert.ToInt32(gig6.idGig) && cd.idAcc == _idCus
                                                 select cd).Count() > 0 ? "collection2" : "collection1"
                                 };

                AspNetPager1.RecordCount = itemGigAll.Count();
                rptAll.DataSource = itemGigAll.Skip(AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1)).Take(AspNetPager1.PageSize);
                rptAll.DataBind();

                // Set link Facebook
                lblTenCate.Text = "Tất cả các danh mục";
                Page.Title = "Vieclamgap.net | Tất cả Danh mục dịch vụ";
                // Load Meta tags
                liter_title.Text = "\n<meta content=\"" + itemGigAll.FirstOrDefault().TenCongViec + "," + itemGigAll.FirstOrDefault().Tags + tagsCate + "\" name=\"description\">" + "\n<meta content=\"" + itemGigAll.FirstOrDefault().TenCongViec + "," + itemGigAll.FirstOrDefault().Tags + tagsCate + "\" name=\"content\">" + "\n<meta content=\"" + itemGigAll.FirstOrDefault().TenCongViec + "," + itemGigAll.FirstOrDefault().TenCongViec_KD + "," + itemGigAll.FirstOrDefault().Tags + tagsCate + "\" name=\"keywords\">";
                // kiem tra co dang nhap ko

            }
            else if (String.IsNullOrEmpty(stCate) == false)
            {
                // Response.Write(_idCus);
                try
                {
                    int idCate = int.Parse(stCate);
                    var itemGig = from gig in _db2.Gigs
                                  where gig.TrangThai == (int)EnumGigStatus.GigHien && gig.idCategory == idCate && gig.Duyet == true
                                  orderby gig.idGig descending
                                  //select gig;
                                  select new
                                  {
                                      gig.idGig,
                                      gig.TenCongViec,
                                      gig.VLGAccount.UsernameE,
                                      gig.idCategory,
                                      gig.UrlHinh1,
                                      gig.MoTaCV,
                                      gig.VLGAccount.ipAddress,
                                      gig.VLGAccount.TenQuocGia,
                                      gig.Tags,
                                      gig.TenCongViec_KD,
                                      gig.Category.TenCate_E,
                                      CssClass = (from cd in _db2.CollectionDetails
                                                  where cd.idGig == Convert.ToInt32(gig.idGig) && cd.idAcc == _idCus
                                                  select cd).Count() > 0 ? "collection2" : "collection1"
                                  };

                    AspNetPager1.RecordCount = itemGig.Count();
                    rptAll.DataSource = itemGig.Skip(AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1)).Take(AspNetPager1.PageSize);
                    rptAll.DataBind();

                    Category catItem = _db2.Categories.Single(sock => sock.AnHien == true && sock.idCategory == idCate);
                    // Tieu đề trang
                    liter_title.Text = "\n<meta content=\"" + itemGig.FirstOrDefault().TenCongViec + "," + itemGig.FirstOrDefault().Tags + "\" name=\"description\">" + "\n<meta content=\"" + itemGig.FirstOrDefault().TenCongViec + "," + itemGig.FirstOrDefault().Tags + "\" name=\"content\">" + "\n<meta content=\"" + itemGig.FirstOrDefault().TenCongViec + "," + itemGig.FirstOrDefault().TenCongViec_KD + "," + itemGig.FirstOrDefault().Tags + "\" name=\"keywords\">";


                    lblTenCate.Text = catItem.TenCate;
                    Page.Title = "Vieclamgap.net | " + catItem.TenCate.ToUpper() + " | " + catItem.Tags;

                }
                catch
                {
                    int idCate = int.Parse(stCate);
                    Category catItem = _db2.Categories.Single(sock => sock.AnHien == true && sock.idCategory == idCate);
                    lblTenCate.Text = catItem.TenCate;
                    Page.Title = "Vieclamgap.net | " + catItem.TenCate.ToUpper() + " | " + catItem.Tags;
                }
            }
            else if (String.IsNullOrEmpty(tukhoa) == false && String.IsNullOrEmpty(tuychon) == false)
            {
                if (tukhoa == "all")
                {
                    if (tuychon == "1")
                    {
                        var itemSem = from s in _db2.Gigs
                                      where s.TrangThai == (int)EnumGigStatus.GigHien && s.Duyet == true
                                      orderby s.NgayTao, s.idGig descending
                                      select new
                                      {
                                          s.idGig,
                                          s.TenCongViec,
                                          s.VLGAccount.UsernameE,
                                          s.idCategory,
                                          s.UrlHinh1,
                                          s.MoTaCV,
                                          s.VLGAccount.ipAddress,
                                          s.VLGAccount.TenQuocGia,
                                          s.TenCongViec_KD,
                                          s.Tags,
                                          s.Category.TenCate_E,
                                          CssClass = (from cd in _db2.CollectionDetails
                                                      where cd.idGig == Convert.ToInt32(s.idGig) && cd.idAcc == _idCus
                                                      select cd).Count() > 0 ? "collection2" : "collection1"
                                      };

                        AspNetPager2.RecordCount = itemSem.Count();
                        rptSearch.DataSource = itemSem.Skip(AspNetPager2.PageSize * (AspNetPager2.CurrentPageIndex - 1)).Take(AspNetPager2.PageSize);
                        rptSearch.DataBind();
                        timkiem.Style.Add("display", "block");
                        lblTenCate.Text = "Kết quả tìm kiếm";
                        // Tieu de trang
                        Page.Title = "Sắp xếp kết quả tự động".ToUpper();
                        liter_title.Text = "\n<meta content=\"" + itemSem.FirstOrDefault().TenCongViec + "," + itemSem.FirstOrDefault().Tags + "\" name=\"description\">" + "\n<meta content=\"" + itemSem.FirstOrDefault().TenCongViec + "," + itemSem.FirstOrDefault().Tags + "\" name=\"content\">" + "\n<meta content=\"" + itemSem.FirstOrDefault().TenCongViec + "," + itemSem.FirstOrDefault().TenCongViec_KD + "," + itemSem.FirstOrDefault().Tags + "\" name=\"keywords\">";
                    }
                    else if (tuychon == "2")
                    {
                        var itemSe2 = from s2 in _db2.Gigs
                                      where s2.TrangThai == (int)EnumGigStatus.GigHien && s2.Duyet == true
                                      select new
                                      {
                                          s2.idGig,
                                          s2.TenCongViec,
                                          s2.VLGAccount.UsernameE,
                                          s2.idCategory,
                                          s2.UrlHinh1,
                                          s2.MoTaCV,
                                          s2.VLGAccount.ipAddress,
                                          s2.VLGAccount.TenQuocGia,
                                          s2.Tags,
                                          s2.TenCongViec_KD,
                                          s2.Category.TenCate_E,
                                          CssClass = (from cd in _db2.CollectionDetails
                                                      where cd.idGig == Convert.ToInt32(s2.idGig) && cd.idAcc == _idCus
                                                      select cd).Count() > 0 ? "collection2" : "collection1"
                                      };

                        AspNetPager2.RecordCount = itemSe2.Count();
                        rptSearch.DataSource = itemSe2.Skip(AspNetPager2.PageSize * (AspNetPager2.CurrentPageIndex - 1)).Take(AspNetPager2.PageSize);
                        rptSearch.DataBind();
                        timkiem.Style.Add("display", "block");
                        lblTenCate.Text = "Kết quả tìm kiếm";
                        // Tieu de trang
                        Page.Title = "Sắp xếp kết quả theo lượt đánh giá".ToUpper();
                        liter_title.Text = "\n<meta content=\"" + itemSe2.FirstOrDefault().TenCongViec + "," + itemSe2.FirstOrDefault().Tags + "\" name=\"description\">" + "\n<meta content=\"" + itemSe2.FirstOrDefault().TenCongViec + "," + itemSe2.FirstOrDefault().Tags + "\" name=\"content\">" + "\n<meta content=\"" + itemSe2.FirstOrDefault().TenCongViec + "," + itemSe2.FirstOrDefault().TenCongViec_KD + "," + itemSe2.FirstOrDefault().Tags + "\" name=\"keywords\">";
                    }
                    else if (tuychon == "3")
                    {
                        var itemSe3 = from s3 in _db2.Gigs
                                      where s3.TrangThai == (int)EnumGigStatus.GigHien && s3.Duyet == true
                                      orderby s3.idGig descending
                                      select new
                                      {
                                          s3.idGig,
                                          s3.idCategory,
                                          s3.TenCongViec,
                                          s3.MoTaCV,
                                          s3.UrlHinh1,
                                          s3.VLGAccount.UsernameE,
                                          s3.VLGAccount.ipAddress,
                                          s3.VLGAccount.TenQuocGia,
                                          s3.Tags,
                                          s3.TenCongViec_KD,
                                          s3.Category.TenCate_E,
                                          CssClass = (from cd in _db2.CollectionDetails
                                                      where cd.idGig == Convert.ToInt32(s3.idGig) && cd.idAcc == _idCus
                                                      select cd).Count() > 0 ? "collection2" : "collection1"
                                      };

                        AspNetPager2.RecordCount = itemSe3.Count();
                        rptSearch.DataSource = itemSe3.Skip(AspNetPager2.PageSize * (AspNetPager2.CurrentPageIndex - 1)).Take(AspNetPager2.PageSize);
                        rptSearch.DataBind();

                        timkiem.Style.Add("display", "block");
                        lblTenCate.Text = "Kết quả tìm kiếm";
                        // Tieu de trang
                        Page.Title = "Sắp xếp kết quả từ mới nhất đến cũ nhất".ToUpper();
                        liter_title.Text = "\n<meta content=\"" + itemSe3.FirstOrDefault().TenCongViec + "," + itemSe3.FirstOrDefault().Tags + "\" name=\"description\">" + "\n<meta content=\"" + itemSe3.FirstOrDefault().TenCongViec + "," + itemSe3.FirstOrDefault().Tags + "\" name=\"content\">" + "\n<meta content=\"" + itemSe3.FirstOrDefault().TenCongViec + "," + itemSe3.FirstOrDefault().TenCongViec_KD + "," + itemSe3.FirstOrDefault().Tags + "\" name=\"keywords\">";
                    }
                    else if (tuychon == "4")
                    {
                        var itemSe44 = from s44 in _db2.Gigs
                                       where s44.TrangThai == (int)EnumGigStatus.GigHien && s44.Duyet == true && s44.LinkVideo != null && s44.LinkVideo != ""
                                       orderby s44.idGig descending
                                       select new
                                       {
                                           s44.idGig,
                                           s44.idCategory,
                                           s44.TenCongViec,
                                           s44.MoTaCV,
                                           s44.UrlHinh1,
                                           s44.VLGAccount.UsernameE,
                                           s44.VLGAccount.ipAddress,
                                           s44.VLGAccount.TenQuocGia,
                                           s44.Tags,
                                           s44.TenCongViec_KD,
                                           s44.Category.TenCate_E,
                                           CssClass = (from cd in _db2.CollectionDetails
                                                       where cd.idGig == Convert.ToInt32(s44.idGig) && cd.idAcc == _idCus
                                                       select cd).Count() > 0 ? "collection2" : "collection1"
                                       };

                        AspNetPager2.RecordCount = itemSe44.Count();
                        rptSearch.DataSource = itemSe44.Skip(AspNetPager2.PageSize * (AspNetPager2.CurrentPageIndex - 1)).Take(AspNetPager2.PageSize);
                        rptSearch.DataBind();
                        timkiem.Style.Add("display", "block");
                        lblTenCate.Text = "Kết quả tìm kiếm";
                        // Tieu de trang
                        Page.Title = "Sắp xếp kết quả theo công việc đã có Video".ToUpper();
                        liter_title.Text = "\n<meta content=\"" + itemSe44.FirstOrDefault().TenCongViec + "," + itemSe44.FirstOrDefault().Tags + "\" name=\"description\">" + "\n<meta content=\"" + itemSe44.FirstOrDefault().TenCongViec + "," + itemSe44.FirstOrDefault().Tags + "\" name=\"content\">" + "\n<meta content=\"" + itemSe44.FirstOrDefault().TenCongViec + "," + itemSe44.FirstOrDefault().TenCongViec_KD + "," + itemSe44.FirstOrDefault().Tags + "\" name=\"keywords\">";
                    }
                }
                else
                {
                    var itemSe3_2 = from s3 in _db2.Gigs
                                    where s3.TrangThai == (int)EnumGigStatus.GigHien && s3.TenCongViec.Contains(tukhoa) && s3.idCategory == int.Parse(tuychon) && s3.Duyet == true
                                    orderby s3.idGig descending
                                    select new
                                    {
                                        s3.idGig,
                                        s3.idCategory,
                                        s3.TenCongViec,
                                        s3.MoTaCV,
                                        s3.UrlHinh1,
                                        s3.VLGAccount.UsernameE,
                                        s3.VLGAccount.ipAddress,
                                        s3.VLGAccount.TenQuocGia,
                                        s3.Tags,
                                        s3.TenCongViec_KD,
                                        s3.Category.TenCate_E,
                                        CssClass = (from cd in _db2.CollectionDetails
                                                    where cd.idGig == Convert.ToInt32(s3.idGig) && cd.idAcc == _idCus
                                                    select cd).Count() > 0 ? "collection2" : "collection1"
                                    };

                    AspNetPager2.RecordCount = itemSe3_2.Count();
                    rptSearch.DataSource = itemSe3_2.Skip(AspNetPager2.PageSize * (AspNetPager2.CurrentPageIndex - 1)).Take(AspNetPager2.PageSize);
                    rptSearch.DataBind();
                    if (itemSe3_2.Count() == 0)
                    {
                        nothing.Style.Add("display", "block");
                    }
                    timkiem.Style.Add("display", "block");
                    lblTenCate.Text = "Kết quả tìm kiếm";

                    // Tieu de trang
                    Page.Title = "Tìm kiếm theo từ khóa " + tukhoa;
                    try
                    {
                        liter_title.Text = "\n<meta content=\"" + itemSe3_2.FirstOrDefault().TenCongViec + "," + itemSe3_2.FirstOrDefault().Tags + "\" name=\"description\">" + "\n<meta content=\"" + itemSe3_2.FirstOrDefault().TenCongViec + "," + itemSe3_2.FirstOrDefault().Tags + "\" name=\"content\">" + "\n<meta content=\"" + itemSe3_2.FirstOrDefault().TenCongViec + "," + itemSe3_2.FirstOrDefault().TenCongViec_KD + "," + itemSe3_2.FirstOrDefault().Tags + "\" name=\"keywords\">";
                    }
                    catch { }
                }
            }
            else if (String.IsNullOrEmpty(tukhoa) == true && String.IsNullOrEmpty(tuychon) == false)
            {
                var itemSe6 = from s in _db2.Gigs
                              where s.TrangThai == (int)EnumGigStatus.GigHien && s.idCategory == int.Parse(tuychon) && s.Duyet == true
                              orderby s.NgayTao descending
                              select new
                              {
                                  s.idGig,
                                  s.idCategory,
                                  s.TenCongViec,
                                  s.MoTaCV,
                                  s.UrlHinh1,
                                  s.VLGAccount.UsernameE,
                                  s.VLGAccount.ipAddress,
                                  s.VLGAccount.TenQuocGia,
                                  s.TenCongViec_KD,
                                  s.Tags,
                                  s.Category.TenCate_E,
                                  CssClass = (from cd in _db2.CollectionDetails
                                              where cd.idGig == Convert.ToInt32(s.idGig) && cd.idAcc == _idCus
                                              select cd).Count() > 0 ? "collection2" : "collection1"
                              };

                AspNetPager2.RecordCount = itemSe6.Count();
                rptSearch.DataSource = itemSe6.Skip(AspNetPager2.PageSize * (AspNetPager2.CurrentPageIndex - 1)).Take(AspNetPager2.PageSize);
                rptSearch.DataBind();
                timkiem.Style.Add("display", "block");
                lblTenCate.Text = "Kết quả tìm kiếm";
                // Tieu de trang
                Page.Title = "Tìm kiếm theo thể loại";
                liter_title.Text = "\n<meta content=\"" + itemSe6.FirstOrDefault().TenCongViec + "," + itemSe6.FirstOrDefault().Tags + "\" name=\"description\">" + "\n<meta content=\"" + itemSe6.FirstOrDefault().TenCongViec + "," + itemSe6.FirstOrDefault().Tags + "\" name=\"content\">" + "\n<meta content=\"" + itemSe6.FirstOrDefault().TenCongViec + "," + itemSe6.FirstOrDefault().TenCongViec_KD + "," + itemSe6.FirstOrDefault().Tags + "\" name=\"keywords\">";
            }
            //hien thi danh sach bo suu tập
            if (_com.Customer != null)
            {
                //var collectionList = from c in _db2.Collections
                //                     where c.idAcc == _com.Customer.idAcc
                //                     select c;
                //if (collectionList != null && collectionList.Count() > 0)
                //{
                //    rptCollection.DataSource = collectionList;
                //    rptCollection.DataBind();
                //}
                pnLogin.Visible = true;
            }
            else pnNotLogin.Visible = true;
        }
        else
        {
            //Response.Write(stCate);
            if (stCate == null && tukhoa == null && tuychon == null)
            {
                //Response.Write(_idCus);
                var itemGigAll = from gig6 in _db2.Gigs
                                 where gig6.TrangThai == (int)EnumGigStatus.GigHien && gig6.Duyet == true
                                 orderby gig6.idGig
                                 select new
                                 {
                                     gig6.idGig,
                                     gig6.TenCongViec,
                                     gig6.VLGAccount.UsernameE,
                                     gig6.idCategory,
                                     gig6.UrlHinh1,
                                     gig6.MoTaCV,
                                     gig6.VLGAccount.ipAddress,
                                     gig6.VLGAccount.TenQuocGia,
                                     gig6.TenCongViec_KD,
                                     gig6.Tags,
                                     gig6.Category.TenCate_E,
                                     CssClass = "collection1"
                                 };

                AspNetPager1.RecordCount = itemGigAll.Count();
                rptAll.DataSource = itemGigAll.Skip(AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1)).Take(AspNetPager1.PageSize);
                rptAll.DataBind();

                // Set link Facebook
                lblTenCate.Text = "Tất cả các danh mục";
                Page.Title = "Vieclamgap.net | Tất cả Danh mục dịch vụ";
                // Load Meta tags
                liter_title.Text = "\n<meta content=\"" + itemGigAll.FirstOrDefault().TenCongViec + "," + itemGigAll.FirstOrDefault().Tags + tagsCate + "\" name=\"description\">" + "\n<meta content=\"" + itemGigAll.FirstOrDefault().TenCongViec + "," + itemGigAll.FirstOrDefault().Tags + tagsCate + "\" name=\"content\">" + "\n<meta content=\"" + itemGigAll.FirstOrDefault().TenCongViec + "," + itemGigAll.FirstOrDefault().TenCongViec_KD + "," + itemGigAll.FirstOrDefault().Tags + tagsCate + "\" name=\"keywords\">";
                // kiem tra co dang nhap ko

            }
            else if (String.IsNullOrEmpty(stCate) == false)
            {
                // Response.Write(_idCus);
                try
                {
                    int idCate = int.Parse(stCate);
                    var itemGig = from gig in _db2.Gigs
                                  where gig.TrangThai == (int)EnumGigStatus.GigHien && gig.idCategory == idCate && gig.Duyet == true
                                  orderby gig.idGig descending
                                  //select gig;
                                  select new { gig.idGig, gig.TenCongViec, gig.VLGAccount.UsernameE, gig.idCategory, gig.UrlHinh1, gig.MoTaCV, gig.VLGAccount.ipAddress, gig.VLGAccount.TenQuocGia, gig.Tags, gig.TenCongViec_KD, gig.Category.TenCate_E, CssClass = "collection1" };

                    AspNetPager1.RecordCount = itemGig.Count();
                    rptAll.DataSource = itemGig.Skip(AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1)).Take(AspNetPager1.PageSize);
                    rptAll.DataBind();

                    Category catItem = _db2.Categories.Single(sock => sock.AnHien == true && sock.idCategory == idCate);
                    // Tieu đề trang
                    liter_title.Text = "\n<meta content=\"" + itemGig.FirstOrDefault().TenCongViec + "," + itemGig.FirstOrDefault().Tags + "\" name=\"description\">" + "\n<meta content=\"" + itemGig.FirstOrDefault().TenCongViec + "," + itemGig.FirstOrDefault().Tags + "\" name=\"content\">" + "\n<meta content=\"" + itemGig.FirstOrDefault().TenCongViec + "," + itemGig.FirstOrDefault().TenCongViec_KD + "," + itemGig.FirstOrDefault().Tags + "\" name=\"keywords\">";


                    lblTenCate.Text = catItem.TenCate;
                    Page.Title = "Vieclamgap.net | " + catItem.TenCate.ToUpper() + " | " + catItem.Tags;

                }
                catch
                {
                    int idCate = int.Parse(stCate);
                    Category catItem = _db2.Categories.Single(sock => sock.AnHien == true && sock.idCategory == idCate);
                    lblTenCate.Text = catItem.TenCate;
                    Page.Title = "Vieclamgap.net | " + catItem.TenCate.ToUpper() + " | " + catItem.Tags;
                }
            }
            else if (String.IsNullOrEmpty(tukhoa) == false && String.IsNullOrEmpty(tuychon) == false)
            {
                if (tukhoa == "all")
                {
                    if (tuychon == "1")
                    {
                        var itemSem = from s in _db2.Gigs
                                      where s.TrangThai == (int)EnumGigStatus.GigHien && s.Duyet == true
                                      orderby s.NgayTao, s.idGig descending
                                      select new { s.idGig, s.TenCongViec, s.VLGAccount.UsernameE, s.idCategory, s.UrlHinh1, s.MoTaCV, s.VLGAccount.ipAddress, s.VLGAccount.TenQuocGia, s.TenCongViec_KD, s.Tags, s.Category.TenCate_E, CssClass = "collection1" };

                        AspNetPager2.RecordCount = itemSem.Count();
                        rptSearch.DataSource = itemSem.Skip(AspNetPager2.PageSize * (AspNetPager2.CurrentPageIndex - 1)).Take(AspNetPager2.PageSize);
                        rptSearch.DataBind();
                        timkiem.Style.Add("display", "block");
                        lblTenCate.Text = "Kết quả tìm kiếm";
                        // Tieu de trang
                        Page.Title = "Sắp xếp kết quả tự động".ToUpper();
                        liter_title.Text = "\n<meta content=\"" + itemSem.FirstOrDefault().TenCongViec + "," + itemSem.FirstOrDefault().Tags + "\" name=\"description\">" + "\n<meta content=\"" + itemSem.FirstOrDefault().TenCongViec + "," + itemSem.FirstOrDefault().Tags + "\" name=\"content\">" + "\n<meta content=\"" + itemSem.FirstOrDefault().TenCongViec + "," + itemSem.FirstOrDefault().TenCongViec_KD + "," + itemSem.FirstOrDefault().Tags + "\" name=\"keywords\">";
                    }
                    else if (tuychon == "2")
                    {
                        var itemSe2 = from s2 in _db2.Gigs
                                      where s2.TrangThai == (int)EnumGigStatus.GigHien && s2.Duyet == true
                                      select new { s2.idGig, s2.TenCongViec, s2.VLGAccount.UsernameE, s2.idCategory, s2.UrlHinh1, s2.MoTaCV, s2.VLGAccount.ipAddress, s2.VLGAccount.TenQuocGia, s2.Tags, s2.TenCongViec_KD, s2.Category.TenCate_E, CssClass = "collection1" };

                        AspNetPager2.RecordCount = itemSe2.Count();
                        rptSearch.DataSource = itemSe2.Skip(AspNetPager2.PageSize * (AspNetPager2.CurrentPageIndex - 1)).Take(AspNetPager2.PageSize);
                        rptSearch.DataBind();
                        timkiem.Style.Add("display", "block");
                        lblTenCate.Text = "Kết quả tìm kiếm";
                        // Tieu de trang
                        Page.Title = "Sắp xếp kết quả theo lượt đánh giá".ToUpper();
                        liter_title.Text = "\n<meta content=\"" + itemSe2.FirstOrDefault().TenCongViec + "," + itemSe2.FirstOrDefault().Tags + "\" name=\"description\">" + "\n<meta content=\"" + itemSe2.FirstOrDefault().TenCongViec + "," + itemSe2.FirstOrDefault().Tags + "\" name=\"content\">" + "\n<meta content=\"" + itemSe2.FirstOrDefault().TenCongViec + "," + itemSe2.FirstOrDefault().TenCongViec_KD + "," + itemSe2.FirstOrDefault().Tags + "\" name=\"keywords\">";
                    }
                    else if (tuychon == "3")
                    {
                        var itemSe3 = from s3 in _db2.Gigs
                                      where s3.TrangThai == (int)EnumGigStatus.GigHien && s3.Duyet == true
                                      orderby s3.idGig descending
                                      select new { s3.idGig, s3.idCategory, s3.TenCongViec, s3.MoTaCV, s3.UrlHinh1, s3.VLGAccount.UsernameE, s3.VLGAccount.ipAddress, s3.VLGAccount.TenQuocGia, s3.Tags, s3.TenCongViec_KD, s3.Category.TenCate_E, CssClass = "collection1" };

                        AspNetPager2.RecordCount = itemSe3.Count();
                        rptSearch.DataSource = itemSe3.Skip(AspNetPager2.PageSize * (AspNetPager2.CurrentPageIndex - 1)).Take(AspNetPager2.PageSize);
                        rptSearch.DataBind();

                        timkiem.Style.Add("display", "block");
                        lblTenCate.Text = "Kết quả tìm kiếm";
                        // Tieu de trang
                        Page.Title = "Sắp xếp kết quả từ mới nhất đến cũ nhất".ToUpper();
                        liter_title.Text = "\n<meta content=\"" + itemSe3.FirstOrDefault().TenCongViec + "," + itemSe3.FirstOrDefault().Tags + "\" name=\"description\">" + "\n<meta content=\"" + itemSe3.FirstOrDefault().TenCongViec + "," + itemSe3.FirstOrDefault().Tags + "\" name=\"content\">" + "\n<meta content=\"" + itemSe3.FirstOrDefault().TenCongViec + "," + itemSe3.FirstOrDefault().TenCongViec_KD + "," + itemSe3.FirstOrDefault().Tags + "\" name=\"keywords\">";
                    }
                    else if (tuychon == "4")
                    {
                        var itemSe44 = from s44 in _db2.Gigs
                                       where s44.TrangThai == (int)EnumGigStatus.GigHien && s44.Duyet == true && s44.LinkVideo != null && s44.LinkVideo != ""
                                       orderby s44.idGig descending
                                       select new { s44.idGig, s44.idCategory, s44.TenCongViec, s44.MoTaCV, s44.UrlHinh1, s44.VLGAccount.UsernameE, s44.VLGAccount.ipAddress, s44.VLGAccount.TenQuocGia, s44.Tags, s44.TenCongViec_KD, s44.Category.TenCate_E, CssClass = "collection1" };

                        AspNetPager2.RecordCount = itemSe44.Count();
                        rptSearch.DataSource = itemSe44.Skip(AspNetPager2.PageSize * (AspNetPager2.CurrentPageIndex - 1)).Take(AspNetPager2.PageSize);
                        rptSearch.DataBind();
                        timkiem.Style.Add("display", "block");
                        lblTenCate.Text = "Kết quả tìm kiếm";
                        // Tieu de trang
                        Page.Title = "Sắp xếp kết quả theo công việc đã có Video".ToUpper();
                        liter_title.Text = "\n<meta content=\"" + itemSe44.FirstOrDefault().TenCongViec + "," + itemSe44.FirstOrDefault().Tags + "\" name=\"description\">" + "\n<meta content=\"" + itemSe44.FirstOrDefault().TenCongViec + "," + itemSe44.FirstOrDefault().Tags + "\" name=\"content\">" + "\n<meta content=\"" + itemSe44.FirstOrDefault().TenCongViec + "," + itemSe44.FirstOrDefault().TenCongViec_KD + "," + itemSe44.FirstOrDefault().Tags + "\" name=\"keywords\">";
                    }
                }
                else
                {
                    var itemSe3_2 = from s3 in _db2.Gigs
                                    where s3.TrangThai == (int)EnumGigStatus.GigHien && s3.TenCongViec.Contains(tukhoa) && s3.idCategory == int.Parse(tuychon) && s3.Duyet == true
                                    orderby s3.idGig descending
                                    select new { s3.idGig, s3.idCategory, s3.TenCongViec, s3.MoTaCV, s3.UrlHinh1, s3.VLGAccount.UsernameE, s3.VLGAccount.ipAddress, s3.VLGAccount.TenQuocGia, s3.Tags, s3.TenCongViec_KD, s3.Category.TenCate_E, CssClass = "collection1" };

                    AspNetPager2.RecordCount = itemSe3_2.Count();
                    rptSearch.DataSource = itemSe3_2.Skip(AspNetPager2.PageSize * (AspNetPager2.CurrentPageIndex - 1)).Take(AspNetPager2.PageSize);
                    rptSearch.DataBind();
                    if (itemSe3_2.Count() == 0)
                    {
                        nothing.Style.Add("display", "block");
                    }
                    timkiem.Style.Add("display", "block");
                    lblTenCate.Text = "Kết quả tìm kiếm";

                    // Tieu de trang
                    Page.Title = "Tìm kiếm theo từ khóa " + tukhoa;
                    try
                    {
                        liter_title.Text = "\n<meta content=\"" + itemSe3_2.FirstOrDefault().TenCongViec + "," + itemSe3_2.FirstOrDefault().Tags + "\" name=\"description\">" + "\n<meta content=\"" + itemSe3_2.FirstOrDefault().TenCongViec + "," + itemSe3_2.FirstOrDefault().Tags + "\" name=\"content\">" + "\n<meta content=\"" + itemSe3_2.FirstOrDefault().TenCongViec + "," + itemSe3_2.FirstOrDefault().TenCongViec_KD + "," + itemSe3_2.FirstOrDefault().Tags + "\" name=\"keywords\">";
                    }
                    catch { }
                }
            }
            else if (String.IsNullOrEmpty(tukhoa) == true && String.IsNullOrEmpty(tuychon) == false)
            {
                var itemSe6 = from s in _db2.Gigs
                              where s.TrangThai == (int)EnumGigStatus.GigHien && s.idCategory == int.Parse(tuychon) && s.Duyet == true
                              orderby s.NgayTao descending
                              select new { s.idGig, s.idCategory, s.TenCongViec, s.MoTaCV, s.UrlHinh1, s.VLGAccount.UsernameE, s.VLGAccount.ipAddress, s.VLGAccount.TenQuocGia, s.TenCongViec_KD, s.Tags, s.Category.TenCate_E, CssClass = "collection1" };

                AspNetPager2.RecordCount = itemSe6.Count();
                rptSearch.DataSource = itemSe6.Skip(AspNetPager2.PageSize * (AspNetPager2.CurrentPageIndex - 1)).Take(AspNetPager2.PageSize);
                rptSearch.DataBind();
                timkiem.Style.Add("display", "block");
                lblTenCate.Text = "Kết quả tìm kiếm";
                // Tieu de trang
                Page.Title = "Tìm kiếm theo thể loại";
                liter_title.Text = "\n<meta content=\"" + itemSe6.FirstOrDefault().TenCongViec + "," + itemSe6.FirstOrDefault().Tags + "\" name=\"description\">" + "\n<meta content=\"" + itemSe6.FirstOrDefault().TenCongViec + "," + itemSe6.FirstOrDefault().Tags + "\" name=\"content\">" + "\n<meta content=\"" + itemSe6.FirstOrDefault().TenCongViec + "," + itemSe6.FirstOrDefault().TenCongViec_KD + "," + itemSe6.FirstOrDefault().Tags + "\" name=\"keywords\">";
            }
            //hien thi danh sach bo suu tập
            if (_com.Customer != null)
            {
                //var collectionList = from c in _db2.Collections
                //                     where c.idAcc == _com.Customer.idAcc
                //                     select c;
                //if (collectionList != null && collectionList.Count() > 0)
                //{
                //    rptCollection.DataSource = collectionList;
                //    rptCollection.DataBind();
                //}
                pnLogin.Visible = true;
            }
            else pnNotLogin.Visible = true;
        }
    }
    protected void btnTiep_Click(object sender, EventArgs e)
    {
        string noidung = TextBox1.Text.ToString().Trim();
        Response.Redirect(ResolveClientUrl("~/qlcongviec.aspx?op=add&to=") + noidung);
    }


    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        loadData();
    }
    protected void AspNetPager2_PageChanged(object sender, EventArgs e)
    {
        loadData();
    }
    /// <summary>
    /// 
    /// </summary>
    /// <param name="collectionName"></param>
    /// <returns>
    /// 0 : lỗi
    /// 1 : lỗi đã tồn tại
    /// 2 : thành công
    /// </returns>
    [WebMethod]
    public static List<CollectionJson> GetCollection(string idGig)
    {
        if (string.IsNullOrEmpty(idGig))
            return null;

        else
        {
            try
            {
                VLGDataContext _dataContext = new VLGDataContext();
                CommonPage _comment = new CommonPage();
                var con = (from c in _dataContext.Collections
                           where c.idAcc == _comment.Customer.idAcc
                           orderby c.TimeInput descending
                           select new CollectionJson
                           {
                               Id = c.idCollection,
                               Name = c.Name,
                               //CssClass=c.CollectionDetails.Select(cd=>cd.idGig==Convert.ToInt32(idGig)).Count()>0?"collected":""
                               CssClass = (from cd in _dataContext.CollectionDetails
                                           where cd.idGig == Convert.ToInt32(idGig) && cd.idCollection == c.idCollection
                                           select cd).Count() > 0 ? "collected" : ""

                           }).ToList();
                if (con != null && con.Count > 0)
                    return con;
                else return null;
            }
            catch
            {
                return null;
            }
        }

    }
    [WebMethod]
    public static GigRequestData FetchGigRequest(int skip, int take)
    {
        var data = new GigRequestData();
        //using (var dc = new VLGDataContext())
        //{
        var dc = new VLGDataContext();
        var query = (from p in dc.GigRequests
                     where p.IsActive == true
                     select new GigRequestJson
                     {
                         idAcc = p.idAcc,
                         Required = p.Required,
                         UserName = p.VLGAccount.UsernameE
                     })
                        .Skip(skip)
                        .Take(take)
                        .ToList();
        data.GigRequestJsons = query;
        data.TotalRecords = (from p in dc.GigRequests
                             where p.IsActive == true
                             select p).Count();
        //lấy tối đa 50 mẩu tin
        data.TotalRecords = data.TotalRecords > 50 ? 50 : data.TotalRecords;
        //}
        return data;
    }
}

public class GigRequestData
{
    public List<GigRequestJson> GigRequestJsons { get; set; }
    public int TotalRecords { get; set; }
}